package cn.thoughtworks.school.services;

import cn.thoughtworks.school.feign.NotificationCenterFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class NotificationCenterService {
    @Autowired
    private NotificationCenterFeign notificationCenterFeign;

    public void updateUnReadToReadById(Long notificationId) {
        notificationCenterFeign.updateUnReadToReadById(notificationId, "unRead");
    }

    public List getNotificationUnRead(Long userId) {
        return notificationCenterFeign.getNotificationUnRead(userId, "unRead").getBody();
    }

    public void addNotification(Map data) {
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        String token = request.getHeader("token");

        notificationCenterFeign.addNotification(data, token);
    }
}
